{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:43:22.643965Z",
     "iopub.status.busy": "2020-10-11T09:43:22.633730Z",
     "iopub.status.idle": "2020-10-11T09:43:29.388652Z",
     "shell.execute_reply": "2020-10-11T09:43:29.386519Z"
    },
    "papermill": {
     "duration": 6.808883,
     "end_time": "2020-10-11T09:43:29.388855",
     "exception": false,
     "start_time": "2020-10-11T09:43:22.579972",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-rw-r--r-- 1 nobody nogroup 727M Sep 25 17:06 ../input/b7ns-final-672-300w-f0-load13-load1-14ep/b7ns_final_672_300w_f0_load13_load1_14ep_fold0_ep4.pth\r\n",
      "-rw-r--r-- 1 nobody nogroup 638M Sep 28 03:48 ../input/b6ns-final-768-300w-f1-load28-5ep-1e-5/b6ns_final_768_300w_f1_load28_5ep_1e-5_fold1_ep5.pth\r\n",
      "-rw-r--r-- 1 nobody nogroup 590M Sep 19 05:16 ../input/b5ns-final-768-300w-f2-load16-20ep/b5ns_final_768_300w_f2_load16_20ep_fold2_ep1.pth\r\n",
      "-rw-r--r-- 1 nobody nogroup 548M Sep 25 05:26 ../input/b4ns-final-768-300w-f0-load16-20ep-load1-20ep/b4ns_final_768_300w_f0_load16_20ep_load1_20ep_fold0_ep4.pth\r\n",
      "-rw-r--r-- 1 nobody nogroup 521M Sep 28 03:49 ../input/b3ns-final-768-300w-f1-load29-5ep5ep/b3ns_final_768_300w_f1_load29_5ep5ep_fold1_ep5.pth\r\n",
      "-rw-r--r-- 1 nobody nogroup 658M Sep 25 17:06 ../input/nest101-final-768-300w-f4-load16-19ep-load1-16ep/nest101_final_768_300w_f4_load16_19ep_load1_16ep_fold4_ep5.pth\r\n",
      "-rw-r--r-- 1 nobody nogroup 535M Sep 28 03:49 ../input/rex20-ddp-final-768-300w-f4-35ep-load20resume/rex20_DDP_final_768_300w_f4_35ep_load20resume_fold4_ep31.pth\r\n",
      "-rw-r--r-- 1 nobody nogroup 638M Sep 25 05:25 ../input/b6ns-ddp-final-512-300w-f1-40ep/b6ns_DDP_final_512_300w_f1_40ep_fold1_ep36.pth\r\n",
      "-rw-r--r-- 1 nobody nogroup 590M Sep 28 03:49 ../input/b5ns-final-768-300w-f2-load33-5ep-3e-5-32g/b5ns_final_768_300w_f2_load33_5ep_3e-5_32G_fold2_ep4.pth\r\n"
     ]
    }
   ],
   "source": [
    "!ls -lrth ../input/b7ns-final-672-300w-f0-load13-load1-14ep/b7ns_final_672_300w_f0_load13_load1_14ep_fold0_ep4.pth\n",
    "!ls -lrth ../input/b6ns-final-768-300w-f1-load28-5ep-1e-5/b6ns_final_768_300w_f1_load28_5ep_1e-5_fold1_ep5.pth\n",
    "!ls -lrth ../input/b5ns-final-768-300w-f2-load16-20ep/b5ns_final_768_300w_f2_load16_20ep_fold2_ep1.pth\n",
    "!ls -lrth ../input/b4ns-final-768-300w-f0-load16-20ep-load1-20ep/b4ns_final_768_300w_f0_load16_20ep_load1_20ep_fold0_ep4.pth\n",
    "!ls -lrth ../input/b3ns-final-768-300w-f1-load29-5ep5ep/b3ns_final_768_300w_f1_load29_5ep5ep_fold1_ep5.pth\n",
    "!ls -lrth ../input/nest101-final-768-300w-f4-load16-19ep-load1-16ep/nest101_final_768_300w_f4_load16_19ep_load1_16ep_fold4_ep5.pth\n",
    "!ls -lrth ../input/rex20-ddp-final-768-300w-f4-35ep-load20resume/rex20_DDP_final_768_300w_f4_35ep_load20resume_fold4_ep31.pth\n",
    "!ls -lrth ../input/b6ns-ddp-final-512-300w-f1-40ep/b6ns_DDP_final_512_300w_f1_40ep_fold1_ep36.pth\n",
    "!ls -lrth ../input/b5ns-final-768-300w-f2-load33-5ep-3e-5-32g/b5ns_final_768_300w_f2_load33_5ep_3e-5_32G_fold2_ep4.pth"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:43:29.476708Z",
     "iopub.status.busy": "2020-10-11T09:43:29.475553Z",
     "iopub.status.idle": "2020-10-11T09:43:29.478491Z",
     "shell.execute_reply": "2020-10-11T09:43:29.477591Z"
    },
    "papermill": {
     "duration": 0.049139,
     "end_time": "2020-10-11T09:43:29.478653",
     "exception": false,
     "start_time": "2020-10-11T09:43:29.429514",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "SKIP_COMMIT = False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:43:29.569742Z",
     "iopub.status.busy": "2020-10-11T09:43:29.568822Z",
     "iopub.status.idle": "2020-10-11T09:43:29.571431Z",
     "shell.execute_reply": "2020-10-11T09:43:29.570724Z"
    },
    "papermill": {
     "duration": 0.0507,
     "end_time": "2020-10-11T09:43:29.571555",
     "exception": false,
     "start_time": "2020-10-11T09:43:29.520855",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "import sys\n",
    "sys.path = [\n",
    "    '../input/geffnet-20200820',\n",
    "    '../input/rexnetv1',\n",
    "    '../input/resnest/ResNeSt-master'    \n",
    "] + sys.path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "_cell_guid": "b1076dfc-b9ad-4769-8c92-a6c4dae69d19",
    "_uuid": "8f2839f25d086af736a60e9eeb907d3b93b6e0e5",
    "execution": {
     "iopub.execute_input": "2020-10-11T09:43:29.662589Z",
     "iopub.status.busy": "2020-10-11T09:43:29.659575Z",
     "iopub.status.idle": "2020-10-11T09:43:33.103388Z",
     "shell.execute_reply": "2020-10-11T09:43:33.102243Z"
    },
    "papermill": {
     "duration": 3.49111,
     "end_time": "2020-10-11T09:43:33.103514",
     "exception": false,
     "start_time": "2020-10-11T09:43:29.612404",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "import os\n",
    "import cv2\n",
    "import glob\n",
    "import math\n",
    "import pickle\n",
    "import numpy as np # linear algebra\n",
    "import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n",
    "import albumentations\n",
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "from tqdm.notebook import tqdm as tqdm\n",
    "\n",
    "import torch\n",
    "from torch.utils.data import DataLoader, Dataset\n",
    "import torch.nn as nn\n",
    "import torch.nn.functional as F\n",
    "\n",
    "import geffnet"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:43:33.170285Z",
     "iopub.status.busy": "2020-10-11T09:43:33.169503Z",
     "iopub.status.idle": "2020-10-11T09:43:43.099288Z",
     "shell.execute_reply": "2020-10-11T09:43:43.098626Z"
    },
    "papermill": {
     "duration": 9.968083,
     "end_time": "2020-10-11T09:43:43.099407",
     "exception": false,
     "start_time": "2020-10-11T09:43:33.131324",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "data_dir = '../input/landmark-recognition-2020/'\n",
    "model_dir = '../input/landmarkmodels/'\n",
    "\n",
    "df = pd.read_csv(os.path.join(data_dir, 'train.csv'))\n",
    "df['filepath'] = df['id'].apply(lambda x: os.path.join(data_dir, 'train', x[0], x[1], x[2], f'{x}.jpg'))\n",
    "df_sub = pd.read_csv(os.path.join(data_dir, 'sample_submission.csv'))\n",
    "\n",
    "df_test = df_sub[['id']].copy()\n",
    "df_test['filepath'] = df_test['id'].apply(lambda x: os.path.join(data_dir, 'test', x[0], x[1], x[2], f'{x}.jpg'))\n",
    "\n",
    "use_metric = True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:43:43.156979Z",
     "iopub.status.busy": "2020-10-11T09:43:43.155991Z",
     "iopub.status.idle": "2020-10-11T09:43:43.158708Z",
     "shell.execute_reply": "2020-10-11T09:43:43.159210Z"
    },
    "papermill": {
     "duration": 0.033621,
     "end_time": "2020-10-11T09:43:43.159357",
     "exception": false,
     "start_time": "2020-10-11T09:43:43.125736",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "device = torch.device('cuda')\n",
    "batch_size = 4\n",
    "num_workers = 4\n",
    "out_dim = 81313 \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "_cell_guid": "79c7e3d0-c299-4dcb-8224-4455121ee9b0",
    "_uuid": "d629ff2d2480ee46fbb7e2d37f6b5fab8052498a",
    "execution": {
     "iopub.execute_input": "2020-10-11T09:43:43.230430Z",
     "iopub.status.busy": "2020-10-11T09:43:43.229567Z",
     "iopub.status.idle": "2020-10-11T09:43:43.232610Z",
     "shell.execute_reply": "2020-10-11T09:43:43.232068Z"
    },
    "papermill": {
     "duration": 0.046207,
     "end_time": "2020-10-11T09:43:43.232712",
     "exception": false,
     "start_time": "2020-10-11T09:43:43.186505",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "transforms_672 = albumentations.Compose([\n",
    "    albumentations.Resize(672, 672),\n",
    "    albumentations.Normalize()\n",
    "])\n",
    "\n",
    "transforms_768 = albumentations.Compose([\n",
    "    albumentations.Resize(768, 768),\n",
    "    albumentations.Normalize()\n",
    "])\n",
    "transforms_512 = albumentations.Compose([\n",
    "    albumentations.Resize(512, 512),\n",
    "    albumentations.Normalize()\n",
    "])\n",
    "\n",
    "\n",
    "class LandmarkDataset(Dataset):\n",
    "    def __init__(self, csv, split, mode, transforms=[transforms_672, transforms_768,transforms_512]):\n",
    "\n",
    "        self.csv = csv.reset_index()\n",
    "        self.split = split\n",
    "        self.mode = mode\n",
    "        self.transform672 = transforms[0]\n",
    "        self.transform768 = transforms[1]\n",
    "        self.transform512 = transforms[2]\n",
    "\n",
    "    def __len__(self):\n",
    "        return self.csv.shape[0]\n",
    "\n",
    "    def __getitem__(self, index):\n",
    "        row = self.csv.iloc[index]\n",
    "        \n",
    "        image = cv2.imread(row.filepath)\n",
    "        image = image[:, :, ::-1]\n",
    "        \n",
    "        res0 = self.transform672(image=image)\n",
    "        image0 = res0['image'].astype(np.float32)\n",
    "        image0 = image0.transpose(2, 0, 1)        \n",
    "\n",
    "        res1 = self.transform768(image=image)\n",
    "        image1 = res1['image'].astype(np.float32)\n",
    "        image1 = image1.transpose(2, 0, 1)    \n",
    "        \n",
    "        res3 = self.transform512(image=image)\n",
    "        image3 = res3['image'].astype(np.float32)        \n",
    "        image3 = image3.transpose(2, 0, 1)   \n",
    "               \n",
    "        \n",
    "        if self.mode == 'test':\n",
    "            return torch.tensor(image0), torch.tensor(image1) , torch.tensor(image3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:43:43.293413Z",
     "iopub.status.busy": "2020-10-11T09:43:43.292512Z",
     "iopub.status.idle": "2020-10-11T09:43:43.613011Z",
     "shell.execute_reply": "2020-10-11T09:43:43.613768Z"
    },
    "papermill": {
     "duration": 0.354941,
     "end_time": "2020-10-11T09:43:43.613959",
     "exception": false,
     "start_time": "2020-10-11T09:43:43.259018",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "500 101\n"
     ]
    }
   ],
   "source": [
    "if df.shape[0] > 100001: # commit\n",
    "    df = df[df.index % 10 == 0].iloc[500:1000].reset_index(drop=True)\n",
    "    df_test = df_test.head(101).copy()\n",
    "\n",
    "dataset_query = LandmarkDataset(df, 'test', 'test')\n",
    "query_loader = torch.utils.data.DataLoader(dataset_query, batch_size=batch_size, num_workers=num_workers)\n",
    "\n",
    "dataset_test = LandmarkDataset(df_test, 'test', 'test')\n",
    "test_loader = torch.utils.data.DataLoader(dataset_test, batch_size=batch_size, num_workers=num_workers)\n",
    "\n",
    "print(len(dataset_query), len(dataset_test))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:43:43.674679Z",
     "iopub.status.busy": "2020-10-11T09:43:43.674034Z",
     "iopub.status.idle": "2020-10-11T09:43:43.908024Z",
     "shell.execute_reply": "2020-10-11T09:43:43.907487Z"
    },
    "papermill": {
     "duration": 0.266254,
     "end_time": "2020-10-11T09:43:43.908133",
     "exception": false,
     "start_time": "2020-10-11T09:43:43.641879",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(torch.Size([3, 672, 672]),\n",
       " torch.Size([3, 768, 768]),\n",
       " torch.Size([3, 512, 512]))"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataset_query[0][0].shape, dataset_query[0][1].shape, dataset_query[0][2].shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "papermill": {
     "duration": 0.030916,
     "end_time": "2020-10-11T09:43:43.967895",
     "exception": false,
     "start_time": "2020-10-11T09:43:43.936979",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "# Model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:43:44.039946Z",
     "iopub.status.busy": "2020-10-11T09:43:44.039040Z",
     "iopub.status.idle": "2020-10-11T09:43:44.043106Z",
     "shell.execute_reply": "2020-10-11T09:43:44.042562Z"
    },
    "papermill": {
     "duration": 0.044578,
     "end_time": "2020-10-11T09:43:44.043247",
     "exception": false,
     "start_time": "2020-10-11T09:43:43.998669",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "class ArcMarginProduct_subcenter(nn.Module):\n",
    "    def __init__(self, in_features, out_features, k=3):\n",
    "        super().__init__()\n",
    "        self.weight = nn.Parameter(torch.FloatTensor(out_features*k, in_features))\n",
    "        self.reset_parameters()\n",
    "        self.k = k\n",
    "        self.out_features = out_features\n",
    "        \n",
    "    def reset_parameters(self):\n",
    "        stdv = 1. / math.sqrt(self.weight.size(1))\n",
    "        self.weight.data.uniform_(-stdv, stdv)\n",
    "        \n",
    "    def forward(self, features):\n",
    "        cosine_all = F.linear(F.normalize(features), F.normalize(self.weight))\n",
    "        cosine_all = cosine_all.view(-1, self.out_features, self.k)\n",
    "        cosine, _ = torch.max(cosine_all, dim=2)\n",
    "        return cosine "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:43:44.122857Z",
     "iopub.status.busy": "2020-10-11T09:43:44.110164Z",
     "iopub.status.idle": "2020-10-11T09:43:44.264144Z",
     "shell.execute_reply": "2020-10-11T09:43:44.262987Z"
    },
    "papermill": {
     "duration": 0.193248,
     "end_time": "2020-10-11T09:43:44.264325",
     "exception": false,
     "start_time": "2020-10-11T09:43:44.071077",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "sigmoid = torch.nn.Sigmoid()\n",
    "class Swish(torch.autograd.Function):\n",
    "    @staticmethod\n",
    "    def forward(ctx, i):\n",
    "        result = i * sigmoid(i)\n",
    "        ctx.save_for_backward(i)\n",
    "        return result\n",
    "    @staticmethod\n",
    "    def backward(ctx, grad_output):\n",
    "        i = ctx.saved_variables[0]\n",
    "        sigmoid_i = sigmoid(i)\n",
    "        return grad_output * (sigmoid_i * (1 + i * (1 - sigmoid_i)))\n",
    "\n",
    "class Swish_module(nn.Module):\n",
    "    def forward(self, x):\n",
    "        return Swish.apply(x)\n",
    "\n",
    "    \n",
    " \n",
    "    \n",
    "class enet_arcface_FINAL(nn.Module):\n",
    "\n",
    "    def __init__(self, enet_type, out_dim):\n",
    "        super(enet_arcface_FINAL, self).__init__()\n",
    "        self.enet = geffnet.create_model(enet_type.replace('-', '_'), pretrained=None)\n",
    "        self.feat = nn.Linear(self.enet.classifier.in_features, 512)\n",
    "        self.swish = Swish_module()\n",
    "        self.metric_classify = ArcMarginProduct_subcenter(512, out_dim)\n",
    "        self.enet.classifier = nn.Identity()\n",
    " \n",
    "    def forward(self, x):\n",
    "        x = self.enet(x)\n",
    "        x = self.swish(self.feat(x))\n",
    "        return F.normalize(x), self.metric_classify(x)\n",
    "    \n",
    "    \n",
    "from rexnetv1 import ReXNetV1\n",
    "from resnest.torch import resnest101    \n",
    "class rex20_arcface(nn.Module):\n",
    "\n",
    "    def __init__(self, enet_type, out_dim, load_pretrained=False):\n",
    "        super(rex20_arcface, self).__init__()\n",
    "        self.enet = ReXNetV1(width_mult=2.0)\n",
    "        if load_pretrained:\n",
    "            pretrain_wts = \"/workspace/rexnetv1_2.0x.pth\"            \n",
    "            sd = torch.load(pretrain_wts)\n",
    "            self.enet.load_state_dict(sd, strict=True)        \n",
    "        \n",
    "        self.feat = nn.Linear(self.enet.output[1].in_channels, 512)\n",
    "        self.swish = Swish_module()\n",
    "        self.metric_classify = ArcMarginProduct_subcenter(512, out_dim)\n",
    "        self.enet.output = nn.Identity()\n",
    "    \n",
    "    def forward(self, x):\n",
    "        x = self.enet(x)\n",
    "        if x.ndim==1: \n",
    "            x = x.unsqueeze(0)          \n",
    "        x = self.swish(self.feat(x))\n",
    "        return F.normalize(x), self.metric_classify(x)    \n",
    "    \n",
    "class nest101_arcface(nn.Module):\n",
    "\n",
    "    def __init__(self, enet_type, out_dim):\n",
    "        super(nest101_arcface, self).__init__()\n",
    "        self.enet = resnest101(pretrained=False)\n",
    "        self.feat = nn.Linear(self.enet.fc.in_features, 512)\n",
    "        self.swish = Swish_module()\n",
    "        self.metric_classify = ArcMarginProduct_subcenter(512, out_dim)\n",
    "        self.enet.fc = nn.Identity()    \n",
    "    def forward(self, x):\n",
    "        x = self.enet(x)\n",
    "        x = self.swish(self.feat(x))\n",
    "        return F.normalize(x), self.metric_classify(x)    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:43:44.328191Z",
     "iopub.status.busy": "2020-10-11T09:43:44.327584Z",
     "iopub.status.idle": "2020-10-11T09:43:44.332263Z",
     "shell.execute_reply": "2020-10-11T09:43:44.331617Z"
    },
    "papermill": {
     "duration": 0.039503,
     "end_time": "2020-10-11T09:43:44.332380",
     "exception": false,
     "start_time": "2020-10-11T09:43:44.292877",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "def load_model(model, model_file):\n",
    "    state_dict = torch.load(model_file)\n",
    "    if \"model_state_dict\" in state_dict.keys():\n",
    "        state_dict = state_dict[\"model_state_dict\"]\n",
    "    state_dict = {k[7:] if k.startswith('module.') else k: state_dict[k] for k in state_dict.keys()}\n",
    "#     del state_dict['metric_classify.weight']\n",
    "    model.load_state_dict(state_dict, strict=True)\n",
    "    print(f\"loaded {model_file}\")\n",
    "    model.eval()    \n",
    "    return model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:43:44.402066Z",
     "iopub.status.busy": "2020-10-11T09:43:44.396977Z",
     "iopub.status.idle": "2020-10-11T09:43:50.967722Z",
     "shell.execute_reply": "2020-10-11T09:43:50.968306Z"
    },
    "papermill": {
     "duration": 6.607825,
     "end_time": "2020-10-11T09:43:50.968475",
     "exception": false,
     "start_time": "2020-10-11T09:43:44.360650",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-rw-r--r-- 1 nobody nogroup 727M Sep 25 17:06 ../input/b7ns-final-672-300w-f0-load13-load1-14ep/b7ns_final_672_300w_f0_load13_load1_14ep_fold0_ep4.pth\r\n",
      "-rw-r--r-- 1 nobody nogroup 638M Sep 28 03:48 ../input/b6ns-final-768-300w-f1-load28-5ep-1e-5/b6ns_final_768_300w_f1_load28_5ep_1e-5_fold1_ep5.pth\r\n",
      "-rw-r--r-- 1 nobody nogroup 590M Sep 19 05:16 ../input/b5ns-final-768-300w-f2-load16-20ep/b5ns_final_768_300w_f2_load16_20ep_fold2_ep1.pth\r\n",
      "-rw-r--r-- 1 nobody nogroup 548M Sep 25 05:26 ../input/b4ns-final-768-300w-f0-load16-20ep-load1-20ep/b4ns_final_768_300w_f0_load16_20ep_load1_20ep_fold0_ep4.pth\r\n",
      "-rw-r--r-- 1 nobody nogroup 521M Sep 28 03:49 ../input/b3ns-final-768-300w-f1-load29-5ep5ep/b3ns_final_768_300w_f1_load29_5ep5ep_fold1_ep5.pth\r\n",
      "-rw-r--r-- 1 nobody nogroup 658M Sep 25 17:06 ../input/nest101-final-768-300w-f4-load16-19ep-load1-16ep/nest101_final_768_300w_f4_load16_19ep_load1_16ep_fold4_ep5.pth\r\n",
      "-rw-r--r-- 1 nobody nogroup 535M Sep 28 03:49 ../input/rex20-ddp-final-768-300w-f4-35ep-load20resume/rex20_DDP_final_768_300w_f4_35ep_load20resume_fold4_ep31.pth\r\n",
      "-rw-r--r-- 1 nobody nogroup 638M Sep 25 05:25 ../input/b6ns-ddp-final-512-300w-f1-40ep/b6ns_DDP_final_512_300w_f1_40ep_fold1_ep36.pth\r\n",
      "-rw-r--r-- 1 nobody nogroup 590M Sep 28 03:49 ../input/b5ns-final-768-300w-f2-load33-5ep-3e-5-32g/b5ns_final_768_300w_f2_load33_5ep_3e-5_32G_fold2_ep4.pth\r\n"
     ]
    }
   ],
   "source": [
    "!ls -lrth ../input/b7ns-final-672-300w-f0-load13-load1-14ep/b7ns_final_672_300w_f0_load13_load1_14ep_fold0_ep4.pth\n",
    "!ls -lrth ../input/b6ns-final-768-300w-f1-load28-5ep-1e-5/b6ns_final_768_300w_f1_load28_5ep_1e-5_fold1_ep5.pth\n",
    "!ls -lrth ../input/b5ns-final-768-300w-f2-load16-20ep/b5ns_final_768_300w_f2_load16_20ep_fold2_ep1.pth\n",
    "!ls -lrth ../input/b4ns-final-768-300w-f0-load16-20ep-load1-20ep/b4ns_final_768_300w_f0_load16_20ep_load1_20ep_fold0_ep4.pth\n",
    "!ls -lrth ../input/b3ns-final-768-300w-f1-load29-5ep5ep/b3ns_final_768_300w_f1_load29_5ep5ep_fold1_ep5.pth\n",
    "!ls -lrth ../input/nest101-final-768-300w-f4-load16-19ep-load1-16ep/nest101_final_768_300w_f4_load16_19ep_load1_16ep_fold4_ep5.pth\n",
    "!ls -lrth ../input/rex20-ddp-final-768-300w-f4-35ep-load20resume/rex20_DDP_final_768_300w_f4_35ep_load20resume_fold4_ep31.pth\n",
    "!ls -lrth ../input/b6ns-ddp-final-512-300w-f1-40ep/b6ns_DDP_final_512_300w_f1_40ep_fold1_ep36.pth\n",
    "!ls -lrth ../input/b5ns-final-768-300w-f2-load33-5ep-3e-5-32g/b5ns_final_768_300w_f2_load33_5ep_3e-5_32G_fold2_ep4.pth"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:43:51.062899Z",
     "iopub.status.busy": "2020-10-11T09:43:51.052935Z",
     "iopub.status.idle": "2020-10-11T09:44:30.762556Z",
     "shell.execute_reply": "2020-10-11T09:44:30.761723Z"
    },
    "papermill": {
     "duration": 39.75932,
     "end_time": "2020-10-11T09:44:30.762700",
     "exception": false,
     "start_time": "2020-10-11T09:43:51.003380",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "loaded ../input/b7ns-final-672-300w-f0-load13-load1-14ep/b7ns_final_672_300w_f0_load13_load1_14ep_fold0_ep4.pth\n",
      "loaded ../input/b6ns-final-768-300w-f1-load28-5ep-1e-5/b6ns_final_768_300w_f1_load28_5ep_1e-5_fold1_ep5.pth\n",
      "loaded ../input/b5ns-final-768-300w-f2-load16-20ep/b5ns_final_768_300w_f2_load16_20ep_fold2_ep1.pth\n",
      "loaded ../input/b4ns-final-768-300w-f0-load16-20ep-load1-20ep/b4ns_final_768_300w_f0_load16_20ep_load1_20ep_fold0_ep4.pth\n",
      "loaded ../input/b3ns-final-768-300w-f1-load29-5ep5ep/b3ns_final_768_300w_f1_load29_5ep5ep_fold1_ep5.pth\n",
      "loaded ../input/nest101-final-768-300w-f4-load16-19ep-load1-16ep/nest101_final_768_300w_f4_load16_19ep_load1_16ep_fold4_ep5.pth\n",
      "loaded ../input/rex20-ddp-final-768-300w-f4-35ep-load20resume/rex20_DDP_final_768_300w_f4_35ep_load20resume_fold4_ep31.pth\n",
      "loaded ../input/b6ns-ddp-final-512-300w-f1-40ep/b6ns_DDP_final_512_300w_f1_40ep_fold1_ep36.pth\n",
      "loaded ../input/b5ns-final-768-300w-f2-load33-5ep-3e-5-32g/b5ns_final_768_300w_f2_load33_5ep_3e-5_32G_fold2_ep4.pth\n"
     ]
    }
   ],
   "source": [
    "model_b7 = enet_arcface_FINAL('tf_efficientnet_b7_ns', out_dim=out_dim).to(device)\n",
    "model_b7 = load_model(model_b7, '../input/b7ns-final-672-300w-f0-load13-load1-14ep/b7ns_final_672_300w_f0_load13_load1_14ep_fold0_ep4.pth')\n",
    "\n",
    "model_b6 = enet_arcface_FINAL('tf_efficientnet_b6_ns', out_dim=out_dim).to(device)\n",
    "model_b6 = load_model(model_b6, '../input/b6ns-final-768-300w-f1-load28-5ep-1e-5/b6ns_final_768_300w_f1_load28_5ep_1e-5_fold1_ep5.pth')\n",
    "\n",
    "model_b5 = enet_arcface_FINAL('tf_efficientnet_b5_ns', out_dim=out_dim).to(device)\n",
    "model_b5 = load_model(model_b5, '../input/b5ns-final-768-300w-f2-load16-20ep/b5ns_final_768_300w_f2_load16_20ep_fold2_ep1.pth')\n",
    "\n",
    "model_b4 = enet_arcface_FINAL('tf_efficientnet_b4_ns', out_dim=out_dim).to(device)\n",
    "model_b4 = load_model(model_b4, '../input/b4ns-final-768-300w-f0-load16-20ep-load1-20ep/b4ns_final_768_300w_f0_load16_20ep_load1_20ep_fold0_ep4.pth')\n",
    "\n",
    "model_b3 = enet_arcface_FINAL('tf_efficientnet_b3_ns', out_dim=out_dim).to(device)\n",
    "model_b3 = load_model(model_b3, '../input/b3ns-final-768-300w-f1-load29-5ep5ep/b3ns_final_768_300w_f1_load29_5ep5ep_fold1_ep5.pth')\n",
    "\n",
    "model_nest101 = nest101_arcface('nest101', out_dim=out_dim).to(device)\n",
    "model_nest101 = load_model(model_nest101, '../input/nest101-final-768-300w-f4-load16-19ep-load1-16ep/nest101_final_768_300w_f4_load16_19ep_load1_16ep_fold4_ep5.pth')\n",
    "\n",
    "model_rex2 = rex20_arcface('rex2.0', out_dim=out_dim).to(device)\n",
    "model_rex2 = load_model(model_rex2, '../input/rex20-ddp-final-768-300w-f4-35ep-load20resume/rex20_DDP_final_768_300w_f4_35ep_load20resume_fold4_ep31.pth')\n",
    "\n",
    "model_b6b = enet_arcface_FINAL('tf_efficientnet_b6_ns', out_dim=out_dim).to(device)\n",
    "model_b6b = load_model(model_b6b, '../input/b6ns-ddp-final-512-300w-f1-40ep/b6ns_DDP_final_512_300w_f1_40ep_fold1_ep36.pth')\n",
    "\n",
    "model_b5b = enet_arcface_FINAL('tf_efficientnet_b5_ns', out_dim=out_dim).to(device)\n",
    "model_b5b = load_model(model_b5b, '../input/b5ns-final-768-300w-f2-load33-5ep-3e-5-32g/b5ns_final_768_300w_f2_load33_5ep_3e-5_32G_fold2_ep4.pth')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:44:30.859136Z",
     "iopub.status.busy": "2020-10-11T09:44:30.858473Z",
     "iopub.status.idle": "2020-10-11T09:44:31.607584Z",
     "shell.execute_reply": "2020-10-11T09:44:31.606451Z"
    },
    "papermill": {
     "duration": 0.809518,
     "end_time": "2020-10-11T09:44:31.607731",
     "exception": false,
     "start_time": "2020-10-11T09:44:30.798213",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Sun Oct 11 09:44:31 2020       \r\n",
      "+-----------------------------------------------------------------------------+\r\n",
      "| NVIDIA-SMI 418.67       Driver Version: 418.67       CUDA Version: 10.1     |\r\n",
      "|-------------------------------+----------------------+----------------------+\r\n",
      "| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |\r\n",
      "| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |\r\n",
      "|===============================+======================+======================|\r\n",
      "|   0  Tesla P100-PCIE...  Off  | 00000000:00:04.0 Off |                    0 |\r\n",
      "| N/A   39C    P0    32W / 250W |   6775MiB / 16280MiB |      0%      Default |\r\n",
      "+-------------------------------+----------------------+----------------------+\r\n",
      "                                                                               \r\n",
      "+-----------------------------------------------------------------------------+\r\n",
      "| Processes:                                                       GPU Memory |\r\n",
      "|  GPU       PID   Type   Process name                             Usage      |\r\n",
      "|=============================================================================|\r\n",
      "+-----------------------------------------------------------------------------+\r\n"
     ]
    }
   ],
   "source": [
    "!nvidia-smi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:44:31.687727Z",
     "iopub.status.busy": "2020-10-11T09:44:31.687064Z",
     "iopub.status.idle": "2020-10-11T09:44:32.155238Z",
     "shell.execute_reply": "2020-10-11T09:44:32.154218Z"
    },
    "papermill": {
     "duration": 0.511078,
     "end_time": "2020-10-11T09:44:32.155362",
     "exception": false,
     "start_time": "2020-10-11T09:44:31.644284",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "with open(os.path.join(model_dir, 'idx2landmark_id.pkl'), 'rb') as fp:\n",
    "    idx2landmark_id = pickle.load(fp)\n",
    "    landmark_id2idx = {idx2landmark_id[idx]: idx for idx in idx2landmark_id.keys()}\n",
    "    \n",
    "pred_mask = pd.Series(df.landmark_id.unique()).map(landmark_id2idx).values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:44:32.246684Z",
     "iopub.status.busy": "2020-10-11T09:44:32.241279Z",
     "iopub.status.idle": "2020-10-11T09:48:09.369153Z",
     "shell.execute_reply": "2020-10-11T09:48:09.365379Z"
    },
    "papermill": {
     "duration": 217.177741,
     "end_time": "2020-10-11T09:48:09.369310",
     "exception": false,
     "start_time": "2020-10-11T09:44:32.191569",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "9202fe87dd8741daad7b5ae6399ae27b",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(FloatProgress(value=0.0, max=125.0), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "3d0a1676968341b68132f3b224190cf2",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(FloatProgress(value=0.0, max=26.0), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "TOP_K = 5\n",
    "CLS_TOP_K = 5\n",
    "if True:\n",
    "    with torch.no_grad():\n",
    "        feats = []\n",
    "        for img0, img1,img3 in tqdm(query_loader): # 672, 768, 512\n",
    "            img0 = img0.cuda()\n",
    "            img1 = img1.cuda()\n",
    "            img3 = img3.cuda()\n",
    "            \n",
    "            feat_b7,_      = model_b7(img0)\n",
    "            feat_b6,_      = model_b6(img1)\n",
    "            feat_b5,_      = model_b5(img1)\n",
    "            feat_b4,_      = model_b4(img1)\n",
    "            feat_b3,_      = model_b3(img1)            \n",
    "            feat_nest101,_ = model_nest101(img1)\n",
    "            feat_rex2,_    = model_rex2(img1)\n",
    "            feat_b6b,_     = model_b6b(img3)\n",
    "            feat_b5b,_     = model_b5b(img1)            \n",
    "            feat = torch.cat([feat_b7,feat_b6,feat_b5,feat_b4,feat_b3,feat_nest101,feat_rex2,feat_b6b,feat_b5b],dim=1)            \n",
    "#             print(feat.shape)\n",
    "            feats.append(feat.detach().cpu())\n",
    "        feats = torch.cat(feats)\n",
    "        feats = feats.cuda()\n",
    "        feat = F.normalize(feat)        \n",
    "\n",
    "        PRODS = []\n",
    "        PREDS = []\n",
    "        PRODS_M = []\n",
    "        PREDS_M = []        \n",
    "        for img0, img1,img3 in tqdm(test_loader):\n",
    "            img0 = img0.cuda()\n",
    "            img1 = img1.cuda()\n",
    "            img3 = img3.cuda()\n",
    "            \n",
    "            probs_m = torch.zeros([4, 81313],device=device)\n",
    "            feat_b7,logits_m      = model_b7(img0); probs_m += logits_m\n",
    "            feat_b6,logits_m      = model_b6(img1); probs_m += logits_m\n",
    "            feat_b5,logits_m      = model_b5(img1); probs_m += logits_m\n",
    "            feat_b4,logits_m      = model_b4(img1); probs_m += logits_m\n",
    "            feat_b3,logits_m      = model_b3(img1) ; probs_m += logits_m\n",
    "            feat_nest101,logits_m = model_nest101(img1); probs_m += logits_m\n",
    "            feat_rex2,logits_m    = model_rex2(img1); probs_m += logits_m\n",
    "            feat_b6b,logits_m     = model_b6b(img3); probs_m += logits_m\n",
    "            feat_b5b,logits_m     = model_b5b(img1) ; probs_m += logits_m\n",
    "            feat = torch.cat([feat_b7,feat_b6,feat_b5,feat_b4,feat_b3,feat_nest101,feat_rex2,feat_b6b,feat_b5b],dim=1)\n",
    "            feat = F.normalize(feat)\n",
    "\n",
    "            probs_m = probs_m/9\n",
    "            probs_m[:, pred_mask] += 1.0\n",
    "            probs_m -= 1.0              \n",
    "\n",
    "            (values, indices) = torch.topk(probs_m, CLS_TOP_K, dim=1)\n",
    "            probs_m = values\n",
    "            preds_m = indices              \n",
    "            PRODS_M.append(probs_m.detach().cpu())\n",
    "            PREDS_M.append(preds_m.detach().cpu())            \n",
    "            \n",
    "            distance = feat.mm(feats.t())\n",
    "            (values, indices) = torch.topk(distance, TOP_K, dim=1)\n",
    "            probs = values\n",
    "            preds = indices    \n",
    "            PRODS.append(probs.detach().cpu())\n",
    "            PREDS.append(preds.detach().cpu())\n",
    "\n",
    "        PRODS = torch.cat(PRODS).numpy()\n",
    "        PREDS = torch.cat(PREDS).numpy()\n",
    "        PRODS_M = torch.cat(PRODS_M).numpy()\n",
    "        PREDS_M = torch.cat(PREDS_M).numpy()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:48:09.453814Z",
     "iopub.status.busy": "2020-10-11T09:48:09.452968Z",
     "iopub.status.idle": "2020-10-11T09:48:10.212164Z",
     "shell.execute_reply": "2020-10-11T09:48:10.210731Z"
    },
    "papermill": {
     "duration": 0.805081,
     "end_time": "2020-10-11T09:48:10.212932",
     "exception": false,
     "start_time": "2020-10-11T09:48:09.407851",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Sun Oct 11 09:48:10 2020       \r\n",
      "+-----------------------------------------------------------------------------+\r\n",
      "| NVIDIA-SMI 418.67       Driver Version: 418.67       CUDA Version: 10.1     |\r\n",
      "|-------------------------------+----------------------+----------------------+\r\n",
      "| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |\r\n",
      "| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |\r\n",
      "|===============================+======================+======================|\r\n",
      "|   0  Tesla P100-PCIE...  Off  | 00000000:00:04.0 Off |                    0 |\r\n",
      "| N/A   69C    P0    47W / 250W |   9443MiB / 16280MiB |      0%      Default |\r\n",
      "+-------------------------------+----------------------+----------------------+\r\n",
      "                                                                               \r\n",
      "+-----------------------------------------------------------------------------+\r\n",
      "| Processes:                                                       GPU Memory |\r\n",
      "|  GPU       PID   Type   Process name                             Usage      |\r\n",
      "|=============================================================================|\r\n",
      "+-----------------------------------------------------------------------------+\r\n"
     ]
    }
   ],
   "source": [
    "!nvidia-smi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:48:10.298202Z",
     "iopub.status.busy": "2020-10-11T09:48:10.297542Z",
     "iopub.status.idle": "2020-10-11T09:48:10.302260Z",
     "shell.execute_reply": "2020-10-11T09:48:10.301700Z"
    },
    "papermill": {
     "duration": 0.049276,
     "end_time": "2020-10-11T09:48:10.302386",
     "exception": false,
     "start_time": "2020-10-11T09:48:10.253110",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "# map both to landmark_id\n",
    "gallery_landmark = df['landmark_id'].values\n",
    "PREDS = gallery_landmark[PREDS]\n",
    "PREDS_M = np.vectorize(idx2landmark_id.get)(PREDS_M)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:48:10.387345Z",
     "iopub.status.busy": "2020-10-11T09:48:10.386510Z",
     "iopub.status.idle": "2020-10-11T09:48:10.390709Z",
     "shell.execute_reply": "2020-10-11T09:48:10.390112Z"
    },
    "papermill": {
     "duration": 0.049313,
     "end_time": "2020-10-11T09:48:10.390823",
     "exception": false,
     "start_time": "2020-10-11T09:48:10.341510",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(624, 1302, 624, 1302)"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "PREDS.min(), PREDS.max(), PREDS_M.min(), PREDS_M.max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:48:10.478714Z",
     "iopub.status.busy": "2020-10-11T09:48:10.477850Z",
     "iopub.status.idle": "2020-10-11T09:48:10.481406Z",
     "shell.execute_reply": "2020-10-11T09:48:10.482002Z"
    },
    "papermill": {
     "duration": 0.050858,
     "end_time": "2020-10-11T09:48:10.482137",
     "exception": false,
     "start_time": "2020-10-11T09:48:10.431279",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 952,  813, 1099,  952, 1200],\n",
       "       [1097,  897,  897,  897,  897],\n",
       "       [ 870,  870,  952,  870, 1085]])"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "PREDS[:3,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:48:10.571383Z",
     "iopub.status.busy": "2020-10-11T09:48:10.570387Z",
     "iopub.status.idle": "2020-10-11T09:48:10.574852Z",
     "shell.execute_reply": "2020-10-11T09:48:10.574328Z"
    },
    "papermill": {
     "duration": 0.052098,
     "end_time": "2020-10-11T09:48:10.574970",
     "exception": false,
     "start_time": "2020-10-11T09:48:10.522872",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 952, 1200,  813,  720,  679],\n",
       "       [ 897, 1097,  656,  742, 1127],\n",
       "       [1056, 1125,  870, 1137,  995]])"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "PREDS_M[:3,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:48:10.663146Z",
     "iopub.status.busy": "2020-10-11T09:48:10.662156Z",
     "iopub.status.idle": "2020-10-11T09:48:10.666713Z",
     "shell.execute_reply": "2020-10-11T09:48:10.666145Z"
    },
    "papermill": {
     "duration": 0.051102,
     "end_time": "2020-10-11T09:48:10.666818",
     "exception": false,
     "start_time": "2020-10-11T09:48:10.615716",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.681755  , 0.35850057, 0.31047723, 0.29391983, 0.2764386 ],\n",
       "       [0.26521137, 0.2481537 , 0.22945951, 0.20242295, 0.19369833],\n",
       "       [0.21629389, 0.19869426, 0.1974397 , 0.19017664, 0.18882267]],\n",
       "      dtype=float32)"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "PRODS[:3,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:48:10.760090Z",
     "iopub.status.busy": "2020-10-11T09:48:10.759015Z",
     "iopub.status.idle": "2020-10-11T09:48:10.763210Z",
     "shell.execute_reply": "2020-10-11T09:48:10.763800Z"
    },
    "papermill": {
     "duration": 0.051306,
     "end_time": "2020-10-11T09:48:10.763967",
     "exception": false,
     "start_time": "2020-10-11T09:48:10.712661",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.1247263 , 0.08313179, 0.07668209, 0.0715282 , 0.06521463],\n",
       "       [0.14809263, 0.06385672, 0.0603286 , 0.05871117, 0.05760074],\n",
       "       [0.07089412, 0.06584203, 0.05534029, 0.05520272, 0.05396509]],\n",
       "      dtype=float32)"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "PRODS_M[:3,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:48:10.882005Z",
     "iopub.status.busy": "2020-10-11T09:48:10.859894Z",
     "iopub.status.idle": "2020-10-11T09:48:10.904138Z",
     "shell.execute_reply": "2020-10-11T09:48:10.903536Z"
    },
    "papermill": {
     "duration": 0.09466,
     "end_time": "2020-10-11T09:48:10.904269",
     "exception": false,
     "start_time": "2020-10-11T09:48:10.809609",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "18f1043af6f64f65a0a604271d0a048a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(FloatProgress(value=0.0, max=101.0), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "PRODS_F = []\n",
    "PREDS_F = []\n",
    "for i in tqdm(range(PREDS.shape[0])):\n",
    "    tmp = {}\n",
    "    classify_dict = {PREDS_M[i,j] : PRODS_M[i,j] for j in range(CLS_TOP_K)}\n",
    "    for k in range(TOP_K):\n",
    "        lid = PREDS[i, k]\n",
    "        tmp[lid] = tmp.get(lid, 0.) + float(PRODS[i, k]) ** 9 * classify_dict.get(lid,1e-8)**10\n",
    "    pred, conf = max(tmp.items(), key=lambda x: x[1])\n",
    "    PREDS_F.append(pred)\n",
    "    PRODS_F.append(conf)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:48:10.997730Z",
     "iopub.status.busy": "2020-10-11T09:48:10.996872Z",
     "iopub.status.idle": "2020-10-11T09:48:11.000468Z",
     "shell.execute_reply": "2020-10-11T09:48:11.001019Z"
    },
    "papermill": {
     "duration": 0.053557,
     "end_time": "2020-10-11T09:48:11.001146",
     "exception": false,
     "start_time": "2020-10-11T09:48:10.947589",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[952, 897, 870, 1121, 689, 1137, 837, 1218, 870, 1302]"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "PREDS_F[:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:48:11.094318Z",
     "iopub.status.busy": "2020-10-11T09:48:11.093377Z",
     "iopub.status.idle": "2020-10-11T09:48:11.097708Z",
     "shell.execute_reply": "2020-10-11T09:48:11.097163Z"
    },
    "papermill": {
     "duration": 0.053124,
     "end_time": "2020-10-11T09:48:11.097810",
     "exception": false,
     "start_time": "2020-10-11T09:48:11.044686",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2.9004050555000624e-11,\n",
       " 3.1895793166577764e-14,\n",
       " 4.968409237027555e-19,\n",
       " 1.4365062829273033e-84,\n",
       " 4.860107542409335e-19,\n",
       " 3.2553560072393107e-19,\n",
       " 5.977784455356364e-19,\n",
       " 2.2891329291418646e-86,\n",
       " 5.941991189154498e-16,\n",
       " 1.1273589838986332e-14]"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "PRODS_F[:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:48:11.192581Z",
     "iopub.status.busy": "2020-10-11T09:48:11.191788Z",
     "iopub.status.idle": "2020-10-11T09:48:11.195106Z",
     "shell.execute_reply": "2020-10-11T09:48:11.194587Z"
    },
    "papermill": {
     "duration": 0.053258,
     "end_time": "2020-10-11T09:48:11.195205",
     "exception": false,
     "start_time": "2020-10-11T09:48:11.141947",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "df_test['pred_id'] = PREDS_F\n",
    "df_test['pred_conf'] = PRODS_F"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:48:11.285611Z",
     "iopub.status.busy": "2020-10-11T09:48:11.284733Z",
     "iopub.status.idle": "2020-10-11T09:48:11.540863Z",
     "shell.execute_reply": "2020-10-11T09:48:11.540124Z"
    },
    "papermill": {
     "duration": 0.302103,
     "end_time": "2020-10-11T09:48:11.540987",
     "exception": false,
     "start_time": "2020-10-11T09:48:11.238884",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "df_sub['landmarks'] = df_test.apply(lambda row: f'{row[\"pred_id\"]} {row[\"pred_conf\"]}', axis=1)\n",
    "df_sub.to_csv('submission.csv', index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-10-11T09:48:11.643276Z",
     "iopub.status.busy": "2020-10-11T09:48:11.642396Z",
     "iopub.status.idle": "2020-10-11T09:48:11.651390Z",
     "shell.execute_reply": "2020-10-11T09:48:11.650790Z"
    },
    "papermill": {
     "duration": 0.063798,
     "end_time": "2020-10-11T09:48:11.651515",
     "exception": false,
     "start_time": "2020-10-11T09:48:11.587717",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>landmarks</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>00084cdf8f600d00</td>\n",
       "      <td>952 2.9004050555000624e-11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000b15b043eb8cf0</td>\n",
       "      <td>897 3.1895793166577764e-14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0011a52f9b948fd2</td>\n",
       "      <td>870 4.968409237027555e-19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>00141b8a5a729084</td>\n",
       "      <td>1121 1.4365062829273033e-84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0018aa4b92532b77</td>\n",
       "      <td>689 4.860107542409335e-19</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 id                    landmarks\n",
       "0  00084cdf8f600d00   952 2.9004050555000624e-11\n",
       "1  000b15b043eb8cf0   897 3.1895793166577764e-14\n",
       "2  0011a52f9b948fd2    870 4.968409237027555e-19\n",
       "3  00141b8a5a729084  1121 1.4365062829273033e-84\n",
       "4  0018aa4b92532b77    689 4.860107542409335e-19"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_sub.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "papermill": {
     "duration": 0.045011,
     "end_time": "2020-10-11T09:48:11.741582",
     "exception": false,
     "start_time": "2020-10-11T09:48:11.696571",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "papermill": {
     "duration": 0.04539,
     "end_time": "2020-10-11T09:48:11.833338",
     "exception": false,
     "start_time": "2020-10-11T09:48:11.787948",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  },
  "papermill": {
   "duration": 295.021532,
   "end_time": "2020-10-11T09:48:13.432186",
   "environment_variables": {},
   "exception": null,
   "input_path": "__notebook__.ipynb",
   "output_path": "__notebook__.ipynb",
   "parameters": {},
   "start_time": "2020-10-11T09:43:18.410654",
   "version": "2.1.0"
  },
  "widgets": {
   "application/vnd.jupyter.widget-state+json": {
    "state": {
     "0d760cfcb6114e91a9d14af9ffd13a09": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "18f1043af6f64f65a0a604271d0a048a": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "HBoxModel",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "HBoxModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "HBoxView",
       "box_style": "",
       "children": [
        "IPY_MODEL_fac2202e5e1d49f7b429f4076a31b4a4",
        "IPY_MODEL_c964ed08f6ed48ab9620240c379c2550"
       ],
       "layout": "IPY_MODEL_29d91e9397fb4b28a6e38f6bed6ca220"
      }
     },
     "29acc4dd66774738ad353cbd4d3bf513": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "29d91e9397fb4b28a6e38f6bed6ca220": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "2c9f1f12928b42659b41e395ef1ce79f": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "326d7b885ff7457489c524da5d26dd2c": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "39352791e48c45c99007b9a1d71f6bde": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "HTMLModel",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "HTMLModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "HTMLView",
       "description": "",
       "description_tooltip": null,
       "layout": "IPY_MODEL_86e0c309ec754a48a9e32b51b75c0ead",
       "placeholder": "​",
       "style": "IPY_MODEL_d9cd0c92c4fd40c9b02ad1e252d6ee5e",
       "value": " 26/26 [00:39&lt;00:00,  1.51s/it]"
      }
     },
     "3d0a1676968341b68132f3b224190cf2": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "HBoxModel",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "HBoxModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "HBoxView",
       "box_style": "",
       "children": [
        "IPY_MODEL_ab4c65199cc94997aa09668229982dd7",
        "IPY_MODEL_39352791e48c45c99007b9a1d71f6bde"
       ],
       "layout": "IPY_MODEL_a8cf072e3f22473cb7fbaddfe0429455"
      }
     },
     "7eaec885e8324db7a2ffcb8c3a299069": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "FloatProgressModel",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "FloatProgressModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "ProgressView",
       "bar_style": "success",
       "description": "100%",
       "description_tooltip": null,
       "layout": "IPY_MODEL_953cda3dd5274a8c9e4051a5716f650a",
       "max": 125.0,
       "min": 0.0,
       "orientation": "horizontal",
       "style": "IPY_MODEL_a144756b3c3b44b7b35694324289e018",
       "value": 125.0
      }
     },
     "86e0c309ec754a48a9e32b51b75c0ead": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "9202fe87dd8741daad7b5ae6399ae27b": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "HBoxModel",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "HBoxModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "HBoxView",
       "box_style": "",
       "children": [
        "IPY_MODEL_7eaec885e8324db7a2ffcb8c3a299069",
        "IPY_MODEL_f6b153a086404128a69a5a4fc901eddb"
       ],
       "layout": "IPY_MODEL_29acc4dd66774738ad353cbd4d3bf513"
      }
     },
     "953cda3dd5274a8c9e4051a5716f650a": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "9b6ebcde1b3a4f09969d52fc9fcfc7bd": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "ProgressStyleModel",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "ProgressStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "bar_color": null,
       "description_width": "initial"
      }
     },
     "a0dfaaf680844f4cb434e78231e3da55": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "ProgressStyleModel",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "ProgressStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "bar_color": null,
       "description_width": "initial"
      }
     },
     "a144756b3c3b44b7b35694324289e018": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "ProgressStyleModel",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "ProgressStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "bar_color": null,
       "description_width": "initial"
      }
     },
     "a8cf072e3f22473cb7fbaddfe0429455": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "ab4c65199cc94997aa09668229982dd7": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "FloatProgressModel",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "FloatProgressModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "ProgressView",
       "bar_style": "success",
       "description": "100%",
       "description_tooltip": null,
       "layout": "IPY_MODEL_326d7b885ff7457489c524da5d26dd2c",
       "max": 26.0,
       "min": 0.0,
       "orientation": "horizontal",
       "style": "IPY_MODEL_9b6ebcde1b3a4f09969d52fc9fcfc7bd",
       "value": 26.0
      }
     },
     "b3bb0866156344d3b692dc43ab7a2860": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "c964ed08f6ed48ab9620240c379c2550": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "HTMLModel",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "HTMLModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "HTMLView",
       "description": "",
       "description_tooltip": null,
       "layout": "IPY_MODEL_b3bb0866156344d3b692dc43ab7a2860",
       "placeholder": "​",
       "style": "IPY_MODEL_f7e2699f575947afb4c4e69f026c9cd7",
       "value": " 101/101 [00:00&lt;00:00, 235.43it/s]"
      }
     },
     "ca899d9b5a8c45578058ffb3c4b19d81": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "DescriptionStyleModel",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "DescriptionStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": ""
      }
     },
     "d9cd0c92c4fd40c9b02ad1e252d6ee5e": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "DescriptionStyleModel",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "DescriptionStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": ""
      }
     },
     "f6b153a086404128a69a5a4fc901eddb": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "HTMLModel",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "HTMLModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "HTMLView",
       "description": "",
       "description_tooltip": null,
       "layout": "IPY_MODEL_2c9f1f12928b42659b41e395ef1ce79f",
       "placeholder": "​",
       "style": "IPY_MODEL_ca899d9b5a8c45578058ffb3c4b19d81",
       "value": " 125/125 [03:39&lt;00:00,  1.75s/it]"
      }
     },
     "f7e2699f575947afb4c4e69f026c9cd7": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "DescriptionStyleModel",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "DescriptionStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": ""
      }
     },
     "fac2202e5e1d49f7b429f4076a31b4a4": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "FloatProgressModel",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "FloatProgressModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "ProgressView",
       "bar_style": "success",
       "description": "100%",
       "description_tooltip": null,
       "layout": "IPY_MODEL_0d760cfcb6114e91a9d14af9ffd13a09",
       "max": 101.0,
       "min": 0.0,
       "orientation": "horizontal",
       "style": "IPY_MODEL_a0dfaaf680844f4cb434e78231e3da55",
       "value": 101.0
      }
     }
    },
    "version_major": 2,
    "version_minor": 0
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
